package com.xmkj.carwash.mine.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.retrofit.methods.ApplyFpMethods;
import com.common.retrofit.subscriber.CommonSubscriber;
import com.common.retrofit.subscriber.SubscriberListener;
import com.common.utils.EmptyUtils;
import com.xmkj.carwash.R;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by chen on 2018/4/1.
 */

public class FaPiaoApplyDetailsActivity extends BaseMvpActivity {
    public static final String TYPE = "type";
    @BindView(R.id.iv_next)
    ImageView ivNext;
    @BindView(R.id.tv_fp_type)
    TextView tvFpType;
    @BindView(R.id.et_shuihao)
    EditText etShuihao;
    @BindView(R.id.et_company_name)
    EditText etCompanyName;
    @BindView(R.id.et_address)
    EditText etAddress;
    @BindView(R.id.et_color)
    EditText etColor;
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.tv_intrue)
    TextView tvIntrue;
    private String type = "";

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_fapiao_apply_details;
    }

    @Override
    protected void onViewCreated() {
        type = getIntent().getStringExtra(TYPE);
        if ("1".equals(type)) {
            tvFpType.setText("专用发票");
        } else {
            tvFpType.setText("普通发票");
        }
    }

    @Override
    protected void doLogicFunc() {
        attachClickListener(tvIntrue);
    }

    @Override
    protected void onViewClicked(View view) {
        if (view.getId() == tvIntrue.getId()) {
            if (EmptyUtils.isEmpty(getEditTextStr(etAddress)) ||
                    EmptyUtils.isEmpty(getEditTextStr(etColor)) ||
                    EmptyUtils.isEmpty(getEditTextStr(etCompanyName)) ||
                    EmptyUtils.isEmpty(getEditTextStr(etPhone)) ||
                    EmptyUtils.isEmpty(getEditTextStr(etShuihao))) {
                showToastMsg("请完整填写信息");
                return;

            }
            gotoApplyFP();
        }
    }

    private void gotoApplyFP() {
        showProgressingDialog();
        CommonSubscriber<Object> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {
                showToastMsg("申请成功");
                showProgressingDialog();
                onBackPressed();
            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });

        ApplyFpMethods.getInstance().addInvoice(subscriber, uid, hashid, type, getEditTextStr(etShuihao), getEditTextStr(etCompanyName), getEditTextStr(etAddress), getEditTextStr(etColor), getEditTextStr(etPhone));
        rxManager.add(subscriber);
    }

    @Override
    protected void setNavigation() {
        setNavigationBack("发票申请");
    }


    @Override
    public void bindKnife() {
        ButterKnife.bind(this);
    }
}
